/*
 * $Id: CraftInfo.java 15 2013-05-16 05:43:09Z antonyhands@gmail.com $
 */
package ru.olympus.antonyhands.ao.data.entities;

import java.util.ArrayList;
import java.util.List;

import ru.olympus.antonyhands.ao.data.AOData;
import ru.olympus.antonyhands.ao.util.StringPair;
import ru.olympus.antonyhands.ao.util.StringUtilities;

/**
 * @author AntonyHands
 * @since 14.02.2012
 */
public class CraftInfo extends ItemExchangeBase
{

    public static final String TAG_NAME = "craft-info";

    private static final String ATTRIBUTE_SKILL = "craft-skill";
    private static final String ATTRIBUTE_LEVEL = "craft-level";
    private static final String ATTRIBUTE_WORKLOAD = "workload";

    private CraftSkill craftSkill;
    private Long workload;
    private Long craftLevel;

    public CraftInfo()
    {
        // for persistence sake
    }

    public CraftInfo(CraftSkill craftSkill, Long craftLevel, Long workload, ItemQuantityPair result, List<ItemQuantityPair> inputItems)
    {
        super(result, inputItems);
        this.craftSkill = craftSkill;
        this.workload = workload;
        this.craftLevel = craftLevel;
    }

    @Override
    public String getTagName()
    {
        return TAG_NAME;
    }

    @Override
    public List<StringPair> getAttributes()
    {
        List<StringPair> list = new ArrayList<StringPair>();
        list.add(new StringPair(ATTRIBUTE_SKILL, craftSkill.getCode()));
        list.add(new StringPair(ATTRIBUTE_LEVEL, craftLevel.toString()));
        list.add(new StringPair(ATTRIBUTE_WORKLOAD, workload.toString()));
        return list;
    }

    @Override
    public void setAttributes(List<StringPair> attributes)
    {
        for (StringPair pair : attributes)
        {
            if (ATTRIBUTE_SKILL.equals(pair.getKey()))
                craftSkill = AOData.getInstance().getCraftSkillByCode(pair.getValue());
            else if (ATTRIBUTE_LEVEL.equals(pair.getKey()))
                craftLevel = StringUtilities.stringToLong(pair.getValue());
            else if (ATTRIBUTE_WORKLOAD.equals(pair.getKey()))
                workload = StringUtilities.stringToLong(pair.getValue());
        }
    }

    public Long getCraftLevel() {
		return craftLevel;
	}

	public CraftSkill getCraftSkill() {
		return craftSkill;
	}

	public Long getWorkload()
	{
		return workload;
	}
	
	/*public CraftInfoDTO getDTO()
    {
    	CraftInfoDTO ci = new CraftInfoDTO();
    	ci.setCraftLevel(StringUtilities.longToString(craftLevel));
    	ci.setCraftSkill(new StringPair(craftSkill.getCode(), craftSkill.getTitle()));
    	List<ItemQuantityDTO> inputItemsDTO = new ArrayList<ItemQuantityDTO>();
    	for (ItemQuantityPair ii : listInputItemsData())
    	{
    		ItemQuantityDTO dto = new ItemQuantityDTO();
    		dto.setCategoryCode(ii.getKey().getItemCategory().getCode());
    		dto.setCode(ii.getKey().getCode());
    		dto.setQuantity(StringUtilities.longToString(ii.getValue()));
    		dto.setTitle(ii.getKey().getTitle());
    		inputItemsDTO.add(dto);
    	}
    	ci.setInputItems(inputItemsDTO);
    	ItemQuantityDTO res = new ItemQuantityDTO();
    	res.setCategoryCode(getResultItem().getItemCategory().getCode());
    	res.setCode(getResultItem().getCode());
    	res.setTitle(getResultItem().getTitle());
    	res.setQuantity(StringUtilities.longToString(getResultItemData().getValue()));
    	ci.setResultItem(res);
    	ci.setWorkload(StringUtilities.longToString(workload));
    	return ci;
    }*/
}